﻿#pragma once
#include "logdef.h"


//NAMESPACE_BEG
enum LOG_MODE {
    MODE_CONSL=1,
    MODE_FILE=2,
    MODE_CUST=4,
};
enum LOG_LEVEL {
    INF = 1,
    WAR = 2,
    ERR = 4,
    FAT = 8,
    BUG = 16,
};

enum LOG_FORMAT {
    DIS_FILE = 1,
    DIS_FUN = 2,
    DIS_LIN = 4,
    DIS_COLOR = 8,
    DIS_TIME = 16,
    DIS_THID = 32,
    DIS_LOG_LEVEL=64,
};


class Device {
public:
    virtual void print(LOG_LEVEL level,const char* file, const char* fun, int64_t line_, uint64_t time, const char* log) = 0;
};
void addDevice(Device* dev);

struct ErrorTrace {
    const char* file_;
    const char* fun_;
    int         line_;
    uint64_t    thrad_id_;
    uint64_t    time_;
    std::string log_;
};

void setLogConfig(const char* save_dir="./log",size_t max_file_size=1024*1024*50,bool open_log_que=true);
void setLogPrintMode(int mode =1);
void setLoggerLevel(int level=31);
void setLogFormat(int format=127);
std::ostream& Info(const char* file, const char* fun, int line);
void Infof(const char* file, const char* fun, int line, const char* format, ...);

std::ostream& Warn(const char* file, const char* fun, int line);
void Warnf(const char* file, const char* fun, int line,const char* format, ...);


std::ostream& Debug(const char* file, const char* fun, int len);
void Debugf(const char* file, const char* fun, int len, const char* format, ...);

std::ostream& Error(const char* file, const char* fun, int len);
void Errorf(const char* file, const char* fun, int len, const char* format, ...);
const ErrorTrace&  GetLastErrorLog();

void LogEnd();


#define CLOG_ERR(format,...)  Errorf(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#define CLOG_INF(format,...)  Infof(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#define CLOG_WAR(format,...)  Warnf(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#define CLOG_BUG(format,...)  Debugf(__FILE__,__FUNCTION__,__LINE__,format,__VA_ARGS__)
#if 1
#define LOG_ERR  Error(__FILE__,__FUNCTION__,__LINE__)
#define LOG_INF  Info(__FILE__,__FUNCTION__,__LINE__)
#define LOG_WAR  Warn(__FILE__,__FUNCTION__,__LINE__)
#define LOG_BUG  Debug(__FILE__,__FUNCTION__,__LINE__)
#else
#define LOG_ERR  std::cerr
#define LOG_INF  std::cerr
#define LOG_WAR  std::cerr
#define LOG_BUG  std::cerr
#endif
//NAMESPACE_END
